<!DOCTYPE html>
<html lang="zh">
<head>
    <title>关键词回复 - 派后台管理系统</title>
    {include file="public/header" /}
</head>
<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header"><h4>搜索</h4></div>
                <div class="card-body">
                    <form class="form-inline searchForm" onsubmit="return false;">
                        <div class="form-group">
                            <label for="keyword">关键词</label>
                            <div class="input-group">
                                <div class="input-group">
                                    <input type="text" class="form-control" id="keyword" value="" name="keyword" placeholder="请输入关键词，序号">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="start_time">创建时间</label>
                            <div class="input-group">
                                <input class="form-control js-datetimepicker" type="text" id="start_time" name="start_time" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="开始时间">
                                <span class="input-group-addon">~</span>
                                <input class="form-control js-datetimepicker" type="text" name="end_time" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="结束时间">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="type">分类</label>
                            <select name="type" id="type" class="form-control">
                                <option value="">所有</option>
                                <option value="text">文字</option>
                                <option value="image">图片</option>
                                <option value="video">视频</option>
                                <option value="audio">音频</option>
                                <option value="news">图文</option>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-success" style="margin: -10px 0 0 10px;" id="search">搜索</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header"><h4>关键词列表</h4></div>
                <div class="card-body">
                    <div id="toolbar" class="toolbar-btn-action">
                        <button id="btn_add" type="button" class="btn btn-primary m-r-5" onclick="location.href='/admin/wechat.wechat_reply/add'">
                            <span class="mdi mdi-plus" aria-hidden="true"></span> 新增
                        </button>
                    </div>
                    <table id="tb_departments"></table>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    $('#tb_departments').bootstrapTable({
        classes: 'table table-bordered table-hover table-striped',
        url: '/admin/wechat.wechat_reply/lst',
        method: 'post',
        dataType : 'json',
        uniqueId: 'id',
        idField: 'id',
        toolbar: '#toolbar',
        // showColumns: true,
        showRefresh: true,
        responseHandler: function (res) {
            return {
                "total": res.count,
                "rows": res.data,
            };
        },
        showToggle: true,
        pagination: true,
        queryParams: function(params) {
            var temp = toArrayList($(".searchForm").serializeArray());
            temp['limit'] = params.limit;
            temp['page'] = (params.offset / params.limit) + 1;
            return temp;
        },
        sidePagination: "server",
        pageNumber: 1,
        pageSize: 20,
        pageList: [20, 50, 100],
        columns: [{ checkbox: true},
            {field: 'id',title: '序号',sortable: true},
            {field: 'keyword',title: '关键词'},
            {field: 'type',title: '回复类型',formatter:function (value,row,index)
                {
                   switch (value) {
                       case 'text':
                           return "文本";
                       case 'image':
                           return "图片";
                       case 'news':
                           return "图文";
                       case 'video':
                           return "视频";
                       case 'audio':
                           return "声音";
                   }
                }},
            {field: 'status',title: '状态',formatter:function (value,row,index) {return value === 1 ? '启用' : '禁用';}},
            {field: 'create_time',title: '创建时间'},
            {field: 'update_time',title: '修改时间'},
            {field: 'operate',title: '操作',formatter: btnGroup,  // 自定义方法
                events: {
                    'click .edit-btn': function (event, value, row, index) {
                        location.href = '/admin/wechat.wechat_reply/edit?id='+row.id
                    },
                    'click .del-btn': function (event, value, row, index) {
                        $.alert({
                            title: '系统提示',
                            content: '删除提醒',
                            buttons: {
                                confirm: {
                                    text: '确认',
                                    btnClass: 'btn-primary',
                                    action: function(){
                                        $.post(url="/admin/wechat.wechat_reply/del",data={"id":row.id},function (res) {
                                            if (res.status == 200) {parent.lightyear.notify('删除成功', 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');$("#tb_departments").bootstrapTable('refresh');}
                                            else parent.lightyear.notify('删除失败', 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
                                        });
                                    }
                                },
                                cancel: {
                                    text: '取消'
                                }
                            }
                        });
                    }
                }
            }],
        onLoadSuccess: function(data){
            $("[data-toggle='tooltip']").tooltip();
        }
    });
    $("#search").click(function () {
        $('#tb_departments').bootstrapTable('refresh', {
            url: '/admin/wechat.wechat_reply/lst',
        });
    });
    // 操作按钮
    function btnGroup (){
        let html =
            '<a href="#!" class="btn btn-xs btn-default m-r-5 edit-btn" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>' +
            '<a href="#!" class="btn btn-xs btn-default del-btn" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>';
        return html;
    }
</script>
</body>
</html>